﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.Collections;
using System.Threading;
using System.Globalization;
using Model;
using GameHelp;
using System.IO;
using helper;
using Intorise.Tools.Process;
using System.Diagnostics;
using Common;

namespace TdyxAutoBot
{
    public partial class MainForm
    {
        //打印信息
        private void writeLineMessage(Account account, string message)
        {
            RichTextBox textBox = null;
            if (account == null)
            {
                textBox = this.txtMessage;
            }
            else
            {
                textBox = (RichTextBox)this.characterTxtboxMap[account];
            }

            if (InvokeRequired)
            {
                this.Invoke(new WriterMessage(writeLineMessageMethod), textBox, message);
            }
            else
            {
                writeLineMessageMethod(textBox, message);
            }
        }

        private void writeLineMessageMethod(RichTextBox textBox, string message)
        {
            if (textBox == null) return;
            if (textBox.Text.Length > 10240)
            {
                textBox.Text = textBox.Text.Remove(0, textBox.Text.Length - 10240);
            }
            textBox.AppendText(message.ToString());
            textBox.AppendText("\r\n");
        }

        //打印助手提示信息
        private void PrintMessage(string message)
        {
            lock (txtMessageLocker)
            {
                if (txtMessage.Text.Length > 10240)
                {
                    txtMessage.Text = txtMessage.Text.Remove(0, txtMessage.Text.Length - 10240);
                }
                txtMessage.AppendText(DateTime.Now.ToString("HH:mm:ss:ffff ")+message + "\r\n");
            }
        }

        //记录助手提示信息
        private void Log(string message)
        {
            Program.Log(message);
        }

        //记录助手提示信息
        private void LogAndPrint(string message)
        {
            Program.Log(message);
            PrintMessage(message);
        }

        //打印数据
        private void PrintData(byte[] datas, int length)
        {
            Log("数据：");
            string s = "";
            for (int i = 0; i < length; i++)
            {
                s += datas[i].ToString("X2") + " ";
            }
            Log(s);
            Log("UTF-8解码：" + Tools.ConvertChar(UTF8Encoding.UTF8.GetString(datas, 0, length)));
        }

        //打印数据
        private void PrintData(string text, byte[] datas, int length)
        {
            string s = "";
            for (int i = 0; i < length; i++)
            {
                s += datas[i].ToString("X2") + " ";
            }

            text = DateTime.Now.ToString("HH:mm:ss:ffff")+" "+text + "\r\n" + s + "\r\n" + "UTF-8解码：" + Tools.ConvertChar(UTF8Encoding.UTF8.GetString(datas, 0, length) + "\r\n\r\n----------------------------------------------------------------------------------------------");
            //text = text + "\r\n" + s + "\r\n" + "UTF-8解码：" + Tools.ConvertChar(Encoding.ASCII.GetString(datas, 0, length));
            LogAndPrint(text);
        }

        //打印数据到控制台
        private void PrintDataConsole(byte[] datas, int length)
        {
            Console.Write("数据：");
            string s = "";
            for (int i = 0; i < length; i++)
            {
                s += datas[i].ToString("X2") + " ";
            }
            Console.WriteLine(s);
            Console.WriteLine("UTF-8解码：" + Tools.ConvertChar(UTF8Encoding.UTF8.GetString(datas, 0, length)));
        }
    }
}
